#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cmath>
using namespace std;
int a[1010][5];
int cnt;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i][1] >> a[i][2] >> a[i][3];
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (abs(a[i][1] - a[j][1]) <= 5 && abs(a[i][2] - a[j][2]) <= 5 && abs(a[i][3] - a[j][3]) <= 5)
			{
				if (abs(a[i][1] + a[i][2] + a[i][3] - a[j][1] - a[j][2] - a[j][3]) <= 10)
					cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}